//加载express模块 
const express = require('express');
//创建web服务器 
const app = express();

app.use(express.urlencoded({ extended: true }));
app.use(express.json());
//get访问根目录，返回nihao 
app.use(express.static(__dirname));
//允许访问静态资源，即将整个server目录设置为静态可访问目录 
app.use(express.static(__dirname));

const userInfoRouter = require('./router/userRouter')
const addressRouter = require('./router/addressRouter');
const adminRouter = require('./router/adminRouter')
const orderRouter = require('./router/orderRouter')



//加载cors跨域中间件
const cors = require('cors')
//注册cors 
app.use(cors())
app.use(userInfoRouter)
app.use(addressRouter)
app.use(adminRouter)
app.use(orderRouter)


//监听4000端口，即web服务器运行在4000端口 
app.listen(4000, () => {
    console.log('server running at 4000')
})